package com.css.gitstats.rest;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.css.gitstats.domain.AuthorList;
import com.css.gitstats.service.GitstatsStatistics;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "Gitstats项目统计")
@RestController
@RequestMapping("${gitstats-context}/gitstatsStatistics")
public class GitstatsStatisticsResource {

	@Resource(name = "${gitstats.service.gitstats-statistics}")
	private GitstatsStatistics gitstatsStatistics;
	
	@ApiOperation("Gitstats获取开发人员提交项目提交活动统计")
	@GetMapping("getAuthorLists")
	public ResponseEntity<List<AuthorList>> getAuthorLists(@RequestParam("projectName") String projectName) {
		List<AuthorList> authorLists = null;
		try {
			authorLists = gitstatsStatistics.getAuthorLists(projectName);
		}catch (Exception e) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(authorLists);
		}
		return ResponseEntity.ok(authorLists);
	}
}
